package dao

import javax.inject.{Inject, Singleton}
import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import scala.concurrent.ExecutionContext.Implicits.global

/**
 * Created by yz on 2018/7/17
 */
@Singleton
class QueryLsJunctionDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends
  HasDatabaseConfigProvider[JdbcProfile] {

  import profile.api._

  def insertAll(rows: List[QueryLsJunctionRow]) = db.run(QueryLsJunction ++= rows).map(_ => ())

  def select(junctionId: String) = db.run(QueryLsJunction.
    filter(_.junctionId === junctionId).result.head)

  def selectAll(geneSymbol: String) = db.run(QueryLsJunction.
    filter(_.geneSymbol === geneSymbol).result)

  def selectAllGeneSymbol = db.run(QueryJunction.
    map(_.geneSymbol).distinct.result.map(_.toList))


  def deleteAll = db.run(QueryLsJunction.delete).map(_ => ())


}
